import os
import tables
from PyQt4.QtGui import QFileDialog

def open_file():
    filename = str(QFileDialog.getOpenFileName())
    if filename:
        print "Opened: ", filename
        return filename

def get_hdf5():
    hdf5_file=tables.openFile(open_file())
    return hdf5_file

def parse_node(node):
	for sub_node in node._f_iterNodes():
		if sub_node._c_classId is 'GROUP':
			print '\t', sub_node, ',', type(sub_node), ',', sub_node._c_classId, '\n'
			parse_node(sub_node)
		else:
			print '\t', sub_node, ',', type(sub_node), ',', sub_node._c_classId
		

def parse_hdf5(hdf5_file):
	for node in hdf5_file.root._f_iterNodes():
		if node._c_classId is 'GROUP':
			
			print node, ',', type(node), ',', node._c_classId, '\n'
			parse_node(node)
		else:
			#The remaining elements are then children
			print node, ',', type(node), ',', node._c_classId, '\n'
		

'''so it looks like a dictionary can be returned by using the 
_v_children command.  This may be useful in iterating through the items.
_c_classId is also usefull for determining what to do...'''
